package cn.yunyichina.provider.sb.task;

import cn.yunyichina.provider.sb.service.impl.DownLoadPatientServiceImpl;
import cn.yunyichina.provider.sb.vo.PatientRequest;
import cn.yunyichina.utils.commons.DateUtils;
import cn.yunyichina.utils.convert.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Created by 15-AK on 2017/9/18.
 */
public class InHospitalPatientInfoDownLoadTask {
    private static Logger logger = LoggerFactory.getLogger(OutMedicalPatientInfoUploadTask.class);

    private final AtomicLong idGen = new AtomicLong();

    public void startUp() {
        long count = idGen.incrementAndGet();
        if (logger.isInfoEnabled()) {
            logger.info("第 " + count + " 次住院获取商保患者信息列表采集开始....................");
        }
        Long statrTime = Calendar.getInstance().getTimeInMillis();
        DownLoadPatientServiceImpl patientSevice = new DownLoadPatientServiceImpl();
        String querybeginTime =DateUtils.getTimesBetween(new Date() ,-1);
        String queryEndTime = DateUtils.dateToString(new Date());

        PatientRequest inHospitalPatientRequest = new PatientRequest();
        inHospitalPatientRequest.setHospitalCode("szszyy");
        inHospitalPatientRequest.setBusinessType("2");
        inHospitalPatientRequest.setBeginTime(querybeginTime);
        inHospitalPatientRequest.setEndTime(queryEndTime);
        patientSevice.getPatientMessage(JsonUtils.toJsonString(inHospitalPatientRequest));

        Long endTime = Calendar.getInstance().getTimeInMillis();
        if (logger.isInfoEnabled()) {
            logger.info("第 " + count + " 次住院获取商保患者信息列表采集结束 ,耗费时间" + (endTime - statrTime) + " Millis");
        }
    }

    public static void main(String[] args) {
        Date date = new Date();
        String querybeginTime = DateUtils.getTimesBetween(date, -1);
        String queryEndTime = DateUtils.dateToString(date);

        System.out.println(querybeginTime);
        System.out.println(queryEndTime);
    }
}
